package serve

import (
	infradb "aquaman/app/infra/db"
	dbinterceptor "aquaman/app/infra/db/interceptors"
	"aquaman/app/infra/grpc/interceptors/cred"
	"aquaman/app/infra/grpc/interceptors/recovery"
	"aquaman/app/infra/log"
	grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
	grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
)

// 有些 interceptors 需要依赖其他组件，在 infra/biz/interceptors 中提供
func gRPCServerOptions(logger *zap.Logger,ctxLogger log.CtxLogger, db *infradb.DB) []grpc.ServerOption{
	return []grpc.ServerOption{
		cred.TLSInterceptor(),
		grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
				grpc_zap.UnaryServerInterceptor(logger),
				grpc_recovery.UnaryServerInterceptor(recovery.Interceptor(ctxLogger)),
				dbinterceptor.UnaryServerInterceptor(db.CtxDB),
			)),
	}
}